<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="DataSources.aspx.vb" Inherits="DataSources" title="AVS: Data Sources" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  <asp:SqlDataSource ID="Vendors" runat="server" ConnectionString="<%$ ConnectionStrings:VendorStatsConnectionString %>"
    SelectCommand="SELECT [VendorId], [Name] FROM [Vendors] ORDER BY [Name]"></asp:SqlDataSource>
  <asp:SqlDataSource ID="DataSource" runat="server"
    ConnectionString="<%$ ConnectionStrings:VendorStatsConnectionString %>"
    DeleteCommand="DeleteDatasource" DeleteCommandType="StoredProcedure"
    InsertCommand="InsertDatasource" InsertCommandType="StoredProcedure"
    SelectCommand="SELECT DataSourceVendor.VendorId, DataSources.DataSourceId, DataSources.DataSource, DataSourceVendor.Manual, DataSourceVendor.DataSourceVendorId, DataSources.AddDate, DataSources.DisplayDataSource FROM DataSources INNER JOIN DataSourceVendor ON DataSources.DataSourceId = DataSourceVendor.DataSourceId WHERE (DataSourceVendor.VendorId = @VendorId) ORDER BY DataSources.DataSource"
    UpdateCommand="update datasources set displaydatasource = @displaydatasource where datasourceid = @datasourceid; update datasourcevendor set manual = @manual where datasourcevendorid = @datasourcevendorid">
    <SelectParameters>
      <asp:ControlParameter ControlID="ddlVendors" Name="VendorId" PropertyName="SelectedValue" />
    </SelectParameters>
    <DeleteParameters>
      <asp:Parameter Name="VendorId" Type="Int32" />
      <asp:Parameter Name="DataSource" Type="String" />
    </DeleteParameters>
    <UpdateParameters>
      <asp:Parameter Name="displaydatasource" />
      <asp:Parameter Name="datasourceid" />
      <asp:Parameter Name="manual" />
      <asp:Parameter Name="datasourcevendorid" />
    </UpdateParameters>
    <InsertParameters>
      <asp:Parameter Name="Vendor" Type="String" />
      <asp:Parameter Name="DataSource" Type="String" />
      <asp:Parameter Name="Manual" Type="Int32" />
      <asp:Parameter Direction="InputOutput" Name="DataSourceId" Type="Int32" />
      <asp:Parameter Direction="InputOutput" Name="DataSourceVendorId" Type="Int32" />
    </InsertParameters>
  </asp:SqlDataSource>
  <br />
  <asp:FormView ID="FormView1" runat="server" DataKeyNames="DataSourceId,DataSourceVendorId"
    DataSourceID="DataSource">
     <InsertItemTemplate>
      VendorId:
      <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="Vendors" DataTextField="Name"
        DataValueField="Name" SelectedValue='<%# Bind("Vendor") %>' Width="203px">
      </asp:DropDownList><br />
      DataSource:
      <asp:TextBox ID="DataSourceTextBox" runat="server" Text='<%# Bind("DataSource") %>'
        Width="288px"></asp:TextBox><br />
      Manual:
      <asp:CheckBox ID="ManualCheckBox" runat="server" Checked='<%# Bind("Manual") %>' /><br />
      <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
        Text="Insert"></asp:LinkButton>
      <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
        Text="Cancel"></asp:LinkButton>
    </InsertItemTemplate>
    <ItemTemplate>
      <asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New"
        Text="Add new datasource"></asp:LinkButton>
    </ItemTemplate>
  </asp:FormView>
  <br />
  <asp:DropDownList ID="ddlVendors" runat="server" AutoPostBack="True" DataSourceID="Vendors"
    DataTextField="Name" DataValueField="VendorId" Width="196px">
  </asp:DropDownList><br />
  <br />
  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="DataSourceId,DataSourceVendorId"
    DataSourceID="DataSource">
    <Columns>
      <asp:CommandField ShowEditButton="True" />
      <asp:BoundField DataField="VendorId" HeaderText="VendorId" SortExpression="VendorId"
        Visible="False" />
      <asp:BoundField DataField="DataSourceId" HeaderText="DataSourceId" InsertVisible="False"
        ReadOnly="True" SortExpression="DataSourceId" Visible="False" />
      <asp:BoundField DataField="DataSource" HeaderText="DataSource" SortExpression="DataSource" ReadOnly="True" />
      <asp:CheckBoxField DataField="Manual" HeaderText="Manual" SortExpression="Manual" />
      <asp:BoundField DataField="DisplayDataSource" HeaderText="DisplayDataSource" SortExpression="DisplayDataSource" />
      <asp:BoundField DataField="AddDate" DataFormatString="{0:d}" HeaderText="AddDate"
         ReadOnly="True" HtmlEncode="False" SortExpression="AddDate" />
      <asp:BoundField DataField="DataSourceVendorId" HeaderText="DataSourceVendorId" InsertVisible="False"
        ReadOnly="True" SortExpression="DataSourceVendorId" Visible="False" />
    </Columns>
  </asp:GridView>
</asp:Content>

